<template>
  <div class="live-one-col-wrap j_akc_ubt" @click="toNext">
    <div v-lazy:background-image="liveBgImage" class="left-box">
      <div class="live-status">
        <!-- 10预告,20直播中, 大于20为结束或者回放 -->
        <div>
          <div v-if="liveObj.liveStatus === 10" class="forcast">
            预告
          </div>
          <div v-else-if="liveObj.liveStatus === 20" class="living">
            <explaining></explaining>
            <span>直播中</span>
          </div>
          <div
            v-else-if="liveObj.liveStatus !== 10 && liveObj.liveStatus !== 20"
            class="review"
          >
            回看
          </div>
        </div>
        <div v-if="liveObj.liveStatus === 10" class="right">
          {{ liveObj.planBeginTime | filterLiveTime }}
        </div>
        <div v-else class="right">
          {{ liveObj.totalViewingCount | filterNum }}观看
        </div>
      </div>
      <like-animation
        v-if="liveObj.liveStatus !== 10"
        :count="liveObj.awesomeCount"
        class="animation__wrap"
      ></like-animation>
    </div>
    <div class="right-box">
      <div class="title">
        {{ liveObj.liveTitle }}
      </div>
      <div class="liver-info">
        <div v-lazy:background-image="liveAvator" class="avatar"></div>
        <span class="name">{{ liveName }}</span>
      </div>
      <div
        v-if="liveObj.showProductList && liveObj.showProductList.length"
        class="goods"
      >
        <div v-lazy:background-image="product1Image" class="goods-item">
          <div v-if="liveObj.showProductList[0].salePrice" class="price">
            ￥{{ Number(liveObj.showProductList[0].salePrice) / 100 }}
          </div>
        </div>
        <div v-lazy:background-image="product2Image" class="goods-item">
          <div class="mask">
            <span v-if="liveObj.totalProductCount > 1">{{
              liveObj.totalProductCount
            }}</span
            ><span>商品</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { LikeAnimation, Explaining } from '@akc/live-h5-sdk';
import { formatImgUrl } from '@/utils/util';

export default {
  name: 'liveOneCol',
  components: {
    explaining: Explaining,
    LikeAnimation
  },
  filters: {
    filterNum(num) {
      if (num > 9999) {
        return `${Number((num / 10000).toFixed(2))}万`;
      }
      return num;
    }
  },
  props: {
    liveObj: {
      type: Object,
      default: () => {}
    }
  },
  computed: {
    liveBgImage() {
      return formatImgUrl(this.liveObj.coverUrl, 200, 200);
    },
    product1Image() {
      const { showProductList } = this.liveObj;
      if (
        showProductList &&
        showProductList.length &&
        showProductList[0].ossUrl
      ) {
        return formatImgUrl(showProductList[0].ossUrl, 64, 64);
      }
      return '';
    },
    product2Image() {
      const { showProductList } = this.liveObj;
      if (
        showProductList &&
        showProductList.length &&
        showProductList[1] &&
        showProductList[1].ossUrl
      ) {
        return formatImgUrl(showProductList[1].ossUrl, 32, 32);
      }
      return '';
    },
    liveAvator() {
      const { activityList, hostAvatar } = this.liveObj;
      if (activityList && activityList.length) {
        return activityList[0].brandLogo;
      }
      return hostAvatar;
    },
    liveName() {
      const { activityList, hostNickName } = this.liveObj;
      if (activityList && activityList.length) {
        return activityList[0].brandName;
      }
      return hostNickName;
    }
  },
  methods: {
    toNext() {
      this.$emit('onToNext');
    }
  }
};
</script>

<style lang="scss" scoped>
.live-one-col-wrap {
  width: 355px;
  height: 200px;
  background: rgba(255, 255, 255, 1);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  margin-top: 10px;

  .left-box {
    width: 200px;
    height: 200px;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    margin-right: 12px;
    position: relative;
  }
  .animation__wrap {
    position: absolute;
    right: 0;
    bottom: 7px;
  }
  .right {
    padding: 0 6px;
    height: 16px;
    background: rgba(0, 0, 0, 1);
    border-radius: 0 8px 8px 0;
    opacity: 0.3;
    display: flex;
    align-items: center;
    font-size: 10px;
    font-family: PingFangSC-Regular;
    color: rgba(255, 255, 255, 1);
    box-sizing: border-box;
  }
  .live-status {
    position: absolute;
    left: 10px;
    top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;

    .living {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 54px;
      height: 16px;
      background: linear-gradient(
        90deg,
        rgba(255, 70, 86, 1) 0%,
        rgba(255, 16, 16, 1) 100%
      );
      border-radius: 88px 0 0 88px;
    }

    .review {
      width: 32px;
      height: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: linear-gradient(
        90deg,
        rgba(165, 18, 255, 1) 0%,
        rgba(104, 18, 255, 1) 100%
      );
      border-radius: 88px 0 0 88px;
    }

    .forcast {
      width: 32px;
      height: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: linear-gradient(
        90deg,
        rgba(253, 132, 49, 1) 0%,
        rgba(255, 60, 0, 1) 100%
      );
      border-radius: 8px 0 0 8px;
    }
  }
  .right-box {
    flex: 1;
    height: 200px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    padding-right: 10px;
    margin-top: 25px;

    .title {
      width: 128px;
      font-size: 16px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      color: rgba(51, 51, 51, 1);
      line-height: 22px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      word-wrap: break-word;
      word-break: break-all;
    }

    .liver-info {
      color: #999999;
      font-size: 12px;
      margin: 8px 0 10px 0;
      display: flex;
      align-items: center;
      justify-content: flex-start;

      .avatar {
        width: 24px;
        height: 24px;
        margin-right: 8px;
        border-radius: 100%;
        background-color: #d8d8d8;
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
      }

      .name {
        width: 100px;
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        word-wrap: break-word;
        word-break: break-all;
      }
    }

    .goods {
      display: flex;
      justify-content: flex-start;

      .goods-item {
        width: 64px;
        height: 64px;
        border-radius: 6px;
        position: relative;
        overflow: hidden;
        margin-right: 4px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-end;
        background-color: #d8d8d8;
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
        color: white;
        font-size: 10px;

        .price {
          position: absolute;
          left: 0;
          bottom: 0;
          right: 0;
          height: 16px;
          font-size: 10px;
          color: rgba(255, 255, 255, 1);
          display: flex;
          flex-direction: row;
          align-items: center;
          justify-content: center;
          background: linear-gradient(
            180deg,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, 0.4) 100%
          );
        }

        .mask {
          position: absolute;
          left: 0;
          right: 0;
          bottom: 0;
          top: 0;
          z-index: 1;
          background: rgba(0, 0, 0, 0.4);
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          line-height: 10px;
        }
      }
    }
  }
}
</style>
